package com.tanhua.server.controller;


import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {
    @Autowired
    private MessagesService messagesService;

    @GetMapping("/userinfo")
    public ResponseEntity<UserInfoVo> userinfo(String huanxinId){
       UserInfoVo vo = messagesService.findUserInfoByHuanXin(huanxinId);
       return ResponseEntity.ok(vo);
    }

//    添加好友
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map){
        Long userId = Long.valueOf(map.get("userId").toString());
        messagesService.contacts(userId);
        return ResponseEntity.ok(null);
    }

//    分页查询联系人列表
    public ResponseEntity contacts(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   String keyword){
       PageResult pr = messagesService.findFriends(page,pagesize,keyword);
       return ResponseEntity.ok(pr);
    }
}
